package it.polimi.jita.cp.block.co;

import it.polimi.jita.cp.block.InputBuilder;
import it.polimi.jita.cp.block.de.DemandEstimatorInput;
import it.polimi.jita.cp.block.de.DemandEstimatorInputBuilder;
import it.polimi.jita.cp.block.pc.PenaltyType;

public class CapacityOptimizatorInputBuilder extends
		InputBuilder<CapacityOptimizatorInput> {

	@Override
	protected CapacityOptimizatorInput createInput() throws Exception {
		CapacityOptimizatorInput input;

		Double maxPenalty = Double.parseDouble(getOptionValue("-mp"));
		Integer virtualCpuNumber = Integer.parseInt(getOptionValue("-nc"));

		Double x0 = Double.parseDouble(getOptionValue("-x0"));
		Double x1 = Double.parseDouble(getOptionValue("-x1"));

		String strX2 = getOptionValue("-x2");
		Double x2 = strX2 != null ? Double.parseDouble(strX2) : null;

		DemandEstimatorInputBuilder capacityEstimatorInputBuilder = new DemandEstimatorInputBuilder();
		DemandEstimatorInput estimateInput = (DemandEstimatorInput) capacityEstimatorInputBuilder
				.createInput(getCl());

		String penaltyTypeStr = getOptionValue("-p");
		PenaltyType penaltyType = PenaltyType.valueOf(penaltyTypeStr
				.toUpperCase());

		input = new CapacityOptimizatorInput(estimateInput, virtualCpuNumber,
				maxPenalty, x0, x1, x2, penaltyType);

		return input;
	}
}
